﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Aierp.Utility
{
    public class ResponseModel
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 错误代码
        /// </summary>
        public string ErrorCode { get; set; }
        /// <summary>
        /// 错误消息內容
        /// </summary>
        public string ErrorMsg { get; set; }

        /// <summary>
        /// 返回对象
        /// </summary>
        public object ResultObject { get; set; }
    }

    public enum ErrorCodeStatus
    {
        OK = 100,
        Failed = 101,
        NotLogin = 102,
        Unauthorized = 103,

    }

    public class ResponseResult
    {
        public static ResponseModel Unauthorized()
        {
            return Create(false, ErrorCodeStatus.Unauthorized, "很抱歉，您没有操作权限！");
        }

        public static ResponseModel Ok()
        {
            return Create(true, ErrorCodeStatus.OK, "操作成功");
        }
        public static ResponseModel Fail()
        {
            return Create(false, ErrorCodeStatus.Failed, "操作失败");
        }

        /// <summary>
        /// 输出正确的回复内容
        /// </summary>
        /// <param name="resultObject"></param>
        /// <returns></returns>
        public static ResponseModel Ok(object resultObject)
        {
            return Create(true, ErrorCodeStatus.OK, "操作成功", resultObject);
        }

        public static ResponseModel SpecifyReason(string message)
        {
            return Create(false, ErrorCodeStatus.Failed, message);
        }

        public static ResponseModel Create(bool isSuccess,  ErrorCodeStatus code,string message, object resultObject=null)
        {
            var response = new ResponseModel();//返回结果
            response.Success = isSuccess;
            response.ErrorCode = ((int)code).ToString();
            response.ErrorMsg = message;
            response.ResultObject = resultObject;
            return response;
        }
    }
}
